﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace HttpClientStudy.Core
{
    /// <summary>
    /// 默认处理器1 - 简单的日志记录
    /// </summary>
    public class LoggingHandler : DelegatingHandler
    {
        protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
        {
            // 记录请求信息
            Console.WriteLine($"Request: {request.Method} {request.RequestUri}");

            // 调用管道中的下一个处理器，并获取响应
            var response = await base.SendAsync(request, cancellationToken);

            // 记录响应信息
            Console.WriteLine($"Response: {response.StatusCode}");

            return response;
        }
    }
}
